package ee.ut.math.tvt.ryhm;

import org.apache.log4j.Logger;

import ee.ut.math.tvt.salessystem.domain.controller.SalesDomainController;
import ee.ut.math.tvt.salessystem.domain.controller.impl.SalesDomainControllerImpl;
import ee.ut.math.tvt.salessystem.ui.ConsoleUI;
import ee.ut.math.tvt.salessystem.ui.SalesSystemUI;

/**
 * @author Margus Hanni
 *
 */
public class Intro {

	private static final Logger log = Logger.getLogger(Intro.class);
	private static final String MODE = "console";

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		final SalesDomainController domainController = new SalesDomainControllerImpl();

		if (args.length == 1 && args[0].equals(MODE)) {
			log.debug("Mode: " + MODE);

			ConsoleUI cui = new ConsoleUI(domainController);
			cui.run();
		} else {
			Thread intro = new Thread(new Runnable() {
				@Override
				public void run() {
					IntroUI introUI = new IntroUI();
					introUI.setResizable(false);
					introUI.setVisible(true);
					introUI.setAlwaysOnTop(true);
					try {
						Thread.sleep(15000);
					} catch (InterruptedException e) {
						log.error(e);
					}
					introUI.setAlwaysOnTop(false);
					introUI.setVisible(false);
				}
			});
			intro.start();

			Thread pos = new Thread(new Runnable() {
				@Override
				public void run() {
					final SalesSystemUI ui = new SalesSystemUI(domainController);
					ui.setVisible(true);
				}
			});
			pos.start();
		}
	}
}
